#include <iostream>
#include <vector>

using namespace std;

class Solution 
{
public:
    int minSubArrayLen(int target, vector<int>& nums) 
    {
        int size = nums.size();
        int min_length = 0;
        for(int i = 0; i < size; i++)
        {
            int sum = 0;
            for(int j = i; j < size; j++)
            {
                sum += nums[j];
                if(sum >= target)
                {
                    if(min_length == 0)
                    {
                        min_length = j - i + 1;
                    }
                    else
                    {
                        min_length = ((j - i + 1) < min_length) ? (j - i + 1) : min_length;
                    }
                    break;
                }
            }
        }
        return min_length;
    }
};

int main()
{
    Solution s;
    
    // 测试案例1：基本测试案例
    vector<int> nums1 = {2, 3, 1, 2, 4, 3};
    int target1 = 7;
    cout << "原始数组: ";
    for(int num : nums1) {
        cout << num << " ";
    }
    cout << endl;
    cout << "目标值: " << target1 << endl;
    
    int result1 = s.minSubArrayLen(target1, nums1);
    cout << "最小子数组长度: " << result1 << endl; // 输出: 2 (子数组 [4,3])
    
    // 测试案例2：找不到满足条件的子数组
    vector<int> nums2 = {1, 1, 1, 1, 1, 1, 1, 1};
    int target2 = 11;
    cout << "\n原始数组: ";
    for(int num : nums2) {
        cout << num << " ";
    }
    cout << endl;
    cout << "目标值: " << target2 << endl;
    
    int result2 = s.minSubArrayLen(target2, nums2);
    cout << "最小子数组长度: " << result2 << endl; // 输出: 0 (找不到满足条件的子数组)
    
    return 0;
}
